package cn.test;

import cn.zhuziym.nvw.Constant;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.jsoup.Connection;
import org.jsoup.Jsoup;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;

/**
 * @author study
 * @version 1.0
 * @date 2020/6/25 10:29
 */
public class Down {

    public static void main(String[] args) throws IOException {
        String url = "https://img.onvshen.com:85/gallery/25332/29594/s/006.jpg";

        Connection conn = Jsoup.connect(url).timeout(50000).ignoreContentType(true);
        conn.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
        conn.header("Accept-Encoding", "gzip, deflate, sdch");
        conn.header("Accept-Language", "zh-CN,zh;q=0.9");
        conn.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");

        conn.followRedirects(true);
        Connection.Response execute = conn.execute();
        System.out.println(execute.statusCode());
        System.out.println(execute.statusCode()==403);
        if (execute.statusCode()==403){

        }
        FileUtils.copyInputStreamToFile(execute.bodyStream(), new File("D:/",FilenameUtils.getName(url)));

        System.out.println(FilenameUtils.getName(url));
    }
}
